home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dme / dgkasl.new.lzh / filereq.c < prev   
C/C++ Source or Header  |  1991-11-15  |  7KB  |  343 lines

  1. /*  FileReq.c
  2.  *
  3.  *  ASL interface
  4.  */
  5.  
  6. #include "defs.h"
  7. #include <stdarg.h>
  8. #include <libraries/asl.h>
  9. #include <clib/asl_protos.h>
  10.  
  11. Prototype void do_arpinsfile (void);
  12. Prototype void do_arpload (void);
  13. Prototype void do_arpsave (void);
  14.  
  15. Prototype void fixfile (char *, char *);
  16. Prototype void splitpath (char *, char *, char *);
  17.  
  18. Prototype void fixdirname(char *);
  19.  
  20. Prototype void do_aslload(void);
  21. Prototype void do_aslsave(void);
  22. Prototype void do_aslinsfile(void);
  23. Prototype void do_aslfont(void);
  24.  
  25. /*
  26.  *  The ASL interface uses the asl.library if it exists, else tries to
  27.  *  use the ARP interfafce.
  28.  */
  29.  
  30. void
  31. do_aslload()
  32. {
  33.     char file[64];
  34.     char dir[64];
  35.  
  36.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  37.  
  38.     splitpath(Ep->Name, file, dir);     /* does this EVER return a DIR? */
  39.  
  40.     fixdirname(dir);
  41.  
  42.     if (FReq) {                /* If we have asl.library & requester */
  43.     if (AslRequestTags((APTR)FReq,
  44.         ASL_Hail,    "DME Load New File",
  45.         ASL_OKText,    "Load",
  46.         ASL_Window,    Ep->Win,
  47.         ASL_FuncFlags,    FILF_NEWIDCMP,
  48.         ASL_Dir,    dir,
  49.         ASL_File,    file,
  50.         ASL_LeftEdge,    Ep->ASLleft,     /* use config coords */
  51.         ASL_TopEdge,    Ep->ASLtop,
  52.         ASL_Width,    Ep->ASLwidth,
  53.         ASL_Height,    Ep->ASLheight,
  54.         TAG_DONE )) {
  55.  
  56.         BPTR newlock;
  57.  
  58.         if (newlock = Lock( FReq->rf_Dir, SHARED_LOCK)) {
  59.         UnLock(CurrentDir(oldlock));
  60.         Ep->dirlock = (long)newlock;
  61.  
  62.         Ep->ASLtop = FReq->rf_TopEdge;        /* save coords */
  63.         Ep->ASLleft = FReq->rf_LeftEdge;
  64.         Ep->ASLwidth = FReq->rf_Width;
  65.         Ep->ASLheight = FReq->rf_Height;
  66.  
  67.         /* fixfile(FReq->rf_File,FReq->rf_Dir); */
  68.         av[0] = (ubyte *)"n";
  69.         av[1] = (ubyte *) FReq->rf_File;
  70.         do_edit();
  71.         return;
  72.         }
  73.     }
  74.     CurrentDir(oldlock);
  75.     }
  76.     else {        /* no asl.library? try ARP */
  77.     do_arpload();
  78.     }
  79. }
  80.  
  81.  
  82. void
  83. do_aslsave()
  84. {
  85.     char file[64];
  86.     char dir[64];
  87.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  88.  
  89.     splitpath(Ep->Name, file, dir);
  90.  
  91.     fixdirname(dir);
  92.  
  93.     if (FReq) {
  94.     if (AslRequestTags( (APTR)FReq,
  95.         ASL_Hail,    "DME Save File",
  96.         ASL_OKText,    "Save",
  97.         ASL_Window,    Ep->Win,
  98.         ASL_FuncFlags,    FILF_NEWIDCMP | FILF_SAVE,
  99.         ASL_Dir,    dir,
  100.         ASL_File,    file,
  101.         ASL_LeftEdge,    Ep->ASLleft,
  102.         ASL_TopEdge,    Ep->ASLtop,
  103.         ASL_Width,    Ep->ASLwidth,
  104.         ASL_Height,    Ep->ASLheight,
  105.         TAG_DONE )) {
  106.  
  107.         CurrentDir(oldlock);
  108.         Ep->ASLtop = FReq->rf_TopEdge;
  109.         Ep->ASLleft = FReq->rf_LeftEdge;
  110.         Ep->ASLwidth = FReq->rf_Width;
  111.         Ep->ASLheight = FReq->rf_Height;
  112.         fixfile( FReq->rf_File, FReq->rf_Dir);
  113.         av[1] = (ubyte *)FReq->rf_File;
  114.         do_saveas();
  115.     } else {
  116.         CurrentDir(oldlock);
  117.     }
  118.     }
  119.     else {
  120.     do_arpsave();
  121.     }
  122. }
  123.  
  124. void
  125. do_aslinsfile()
  126. {
  127.     char file[64];
  128.     char dir[64];
  129.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  130.  
  131.     splitpath(Ep->Name, file, dir);
  132.  
  133.     fixdirname(dir);
  134.  
  135.     if (FReq) {
  136.     if (AslRequestTags( (APTR)FReq,
  137.         ASL_Hail,    "DME Insert File",
  138.         ASL_OKText,    "Load",
  139.         ASL_Window,    Ep->Win,
  140.         ASL_FuncFlags,    FILF_NEWIDCMP,
  141.         ASL_Dir,    dir,
  142.         ASL_File,    file,
  143.         ASL_LeftEdge,    Ep->ASLleft,
  144.         ASL_TopEdge,    Ep->ASLtop,
  145.         ASL_Width,    Ep->ASLwidth,
  146.         ASL_Height,    Ep->ASLheight,
  147.         TAG_DONE )) {
  148.  
  149.         CurrentDir(oldlock);
  150.         Ep->ASLtop = FReq->rf_TopEdge;
  151.         Ep->ASLleft = FReq->rf_LeftEdge;
  152.         Ep->ASLwidth = FReq->rf_Width;
  153.         Ep->ASLheight = FReq->rf_Height;
  154.         fixfile( FReq->rf_File, FReq->rf_Dir);
  155.         av[0] = (ubyte *)"i";
  156.         av[1] = (ubyte *)FReq->rf_File;
  157.         do_edit();
  158.         return;
  159.     }
  160.     CurrentDir(oldlock);
  161.     }
  162.     else {
  163.     do_arpinsfile();
  164.     }
  165. }
  166.  
  167. void
  168. do_aslfont()
  169. {
  170.     if (FReq) {
  171.     struct FontRequester *fontreq;
  172.  
  173.     struct Window *fwin = Ep->Win;    /* put ASL on correct screen */
  174.  
  175.     struct TagItem FontTags[] = {    /* DICE 2.06.37 allows us to initialize this here... */
  176.         ASL_Hail,        "DME fixed width font",
  177.         ASL_Window,     fwin,
  178.         ASL_FuncFlags,  FILF_NEWIDCMP | FONF_FIXEDWIDTH,
  179.         ASL_MinHeight,  6,
  180.         ASL_MaxHeight,  24,     /* more than reasonable, eh? */
  181.         TAG_DONE };
  182.  
  183.     if (fontreq = (struct FontRequester *)
  184.               AllocAslRequest(ASL_FontRequest,FontTags) ) {
  185.  
  186.         if (AslRequest(fontreq, NULL)) {
  187.  
  188.         /*  Since we have GetFont() already, just pass
  189.          *   the name and size from fontreq's TextAttr to it.
  190.          *
  191.          *  What follows mimics SETFONT (in cmnd3.c)
  192.          */
  193.  
  194.         FONT *font = (FONT *)GetFont( fontreq->fo_Attr.ta_Name,
  195.                          (short) fontreq->fo_Attr.ta_YSize );
  196.         ED *ep = Ep;
  197.         if (font) {
  198.             text_sync();
  199.             if (ep->Font)
  200.             CloseFont(ep->Font);
  201.             ep->Font = font;
  202.             SetFont(ep->Win->RPort, font);
  203.             SetRast(ep->Win->RPort, 0);
  204.             RefreshWindowFrame(ep->Win);
  205.             set_window_params();
  206.             text_redisplay();
  207.         } else {
  208.             title("Unable to find font");
  209.         }
  210.         }
  211.         FreeAslRequest(fontreq);
  212.     }
  213.     } else {
  214.     title("Need ASL.LIBRARY for Font Requester!");
  215.     }
  216. }
  217.  
  218. /*  this little kludge gets a DIR: string for the ASL requester
  219.  */
  220.  
  221. void
  222. fixdirname(char *dir)
  223. {
  224.     if (!strlen(dir)) {                 /* if no DIR; KLUDGE ALERT! */
  225.  
  226.     if (NameFromLock((BPTR)Ep->dirlock, dir, 64)!=DOSTRUE) {
  227.  
  228.         dir[0] = 0; /* assumes NameFromLock doeesn't clean up on err(??) */
  229.     }
  230.     }
  231. }
  232.  
  233.  
  234. void do_arpinsfile()
  235. {
  236.     char file[64];
  237.     char dir[64];
  238.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  239.     splitpath(Ep->Name, file, dir);
  240.     if (arpreq("Insert File", file, dir, NULL)) {
  241.     CurrentDir(oldlock);
  242.     fixfile(file, dir);
  243.     av[0] = (ubyte *)"i";
  244.     av[1] = (ubyte *)file;
  245.     do_edit();
  246.     return;
  247.     }
  248.     CurrentDir(oldlock);
  249. }
  250.  
  251. void do_arpload()
  252. {
  253.     char file[64];
  254.     char dir[64];
  255.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  256.     splitpath(Ep->Name, file, dir);
  257.     if (arpreq("New File", file, dir, NULL)) {
  258.     BPTR newlock;
  259.     if (newlock = Lock(dir, SHARED_LOCK)) {
  260.         UnLock(CurrentDir(oldlock));
  261.         Ep->dirlock = (long)newlock;
  262.         /* fixfile(file,dir); */
  263.         av[0] = (ubyte *)"n";
  264.         av[1] = (ubyte *)file;
  265.         do_edit();
  266.         return;
  267.     }
  268.     }
  269.     CurrentDir(oldlock);
  270. }
  271.  
  272. void do_arpsave()
  273. {
  274.     char file[64];
  275.     char dir[64];
  276.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  277.     splitpath(Ep->Name, file, dir);
  278.     if (arpreq("Save File", file, dir, NULL)) {
  279.     CurrentDir(oldlock);
  280.     fixfile(file,dir);
  281.     av[1] = (ubyte *)file;
  282.     do_saveas();
  283.     } else {
  284.     CurrentDir(oldlock);
  285.     }
  286. }
  287.  
  288. void
  289. fixfile(file,dir)
  290. char *file,*dir;
  291. {
  292.     char *ptr;
  293.     short len = strlen(dir);
  294.     char hasdev = 0;
  295.  
  296.     /*
  297.      *    do we need to add a slash to the directory spec?
  298.      */
  299.  
  300.     if (len && dir[len-1] != '/' && dir[len-1] != ':') {
  301.     dir[len++] = '/';
  302.     dir[len] = 0;
  303.     }
  304.  
  305.     /*
  306.      *    Is file spec really a full path spec?
  307.      */
  308.  
  309.     for (ptr = file; *ptr; ++ptr) {
  310.     if (ptr[0] == ':')
  311.         hasdev = 1;
  312.     }
  313.     if (!hasdev) {
  314.     movmem(file,file+len,strlen(file)+1);
  315.     movmem(dir,file,len);
  316.     }
  317. }
  318.  
  319. /*
  320.  *  Search backwards for first ':' or '/' and split path there.
  321.  *  This subroutine may appear to be coded incorrectly to a novice
  322.  *  programmer.  It isn't [now].
  323.  */
  324.  
  325. void
  326. splitpath(name, file, dir)
  327. char *name;
  328. char *file, *dir;
  329. {
  330.     short i;
  331.  
  332.     for (i = strlen(name); i >= 0; --i) {       /* was (incorrectly) "i > 0" */
  333.     if (name[i] == ':' || name[i] == '/')
  334.         break;
  335.     }
  336.     ++i;
  337.     strcpy(file, name + i);
  338.     movmem(name, dir, i);
  339.     dir[i] = 0;
  340. }
  341.  
  342. /* EOF */
  343.